import gtk, pygtk
pygtk.require('2.0')

class EntryDialog( gtk.Dialog):

	def __init__(self, message="", default_text='', modal= True):
		gtk.Dialog.__init__(self)
		self.connect("destroy", self.quit)
		self.connect("delete_event", self.quit)
		if modal:
			self.set_modal(True)
			box = gtk.VBox(spacing=10)
			box.set_border_width(10)
			self.vbox.pack_start(box)
			box.show()
		if message:
			label = gtk.Label(message)
			box.pack_start(label)
			label.show()
		self.entry = gtk.Entry()
		self.entry.connect("activate", self.click)
		self.entry.set_text(default_text)
		box.pack_start(self.entry)
		self.entry.show()
		self.entry.grab_focus()
		button = gtk.Button("OK")
		button.connect("clicked", self.click)
		button.set_flags(gtk.CAN_DEFAULT)
		self.action_area.pack_start(button)
		button.show()
		button.grab_default()
		self.ret = None

	def quit(self, w=None, event=None):
		self.hide()
		self.destroy()
		gtk.main_quit()

	def click(self, button):
		self.ret = self.entry.get_text()
		self.quit()
